package com.iot08.api.controller;

import com.iot08.api.controller.base.BaseController;
import com.iot08.api.service.DeviceTokenService;
import com.iot08.common.utils.response.ResponseMap;
import com.iot08.api.vo.request.RelatedAccountReqVO;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @version 1.0
 * @Description:
 * @time: 2020/11/23 9:16
 * @author: Rock
 */
@RestController
@RequestMapping("getway/devicetoken")
public class DeviceTokenController extends BaseController {

    @Resource
    private DeviceTokenService deviceTokenService;

    /**
     * 绑定账号
     *
     * @param vo
     * @param bindingResult
     * @param packageName
     * @time: 2020/11/26 10:45
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("/{devicetoken}/related-account")
    public ResponseMap relatedAccount(@Validated RelatedAccountReqVO vo, BindingResult bindingResult,
                                      @RequestParam(value = "package", required = true) String packageName) {
        vo.setPackageName(packageName);
        return deviceTokenService.relatedAccount(vo);
    }

    /**
     * 清除绑定账号
     *
     * @param devicetoken
     * @param openid
     * @time: 2020/11/26 10:08
     * @author: Rock
     * @version 1.0
     */
    @DeleteMapping("/{devicetoken}/related-account")
    public ResponseMap delRelatedAccount(@PathVariable("devicetoken") String devicetoken,
                                         @RequestParam(value = "openid", required = true) String openid) {

        return deviceTokenService.delRelatedAccount(devicetoken, openid);
    }

}
